package com.xiaohai.exceptionhandle.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaohai.exceptionhandle.common.JsonResponse;
import com.xiaohai.exceptionhandle.common.StatusCode;
import com.xiaohai.exceptionhandle.entity.User;
import com.xiaohai.exceptionhandle.exception.BussnessException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("hello")
public class HelloController {

    @RequestMapping("say")
    public ResponseEntity sayHello(){
        if(true){
//            throw new BussnessException();
        }
        ResponseEntity<User> ok = ResponseEntity.ok(new User());
        return ResponseEntity.ok(new User());
//        return JsonResponse.OK(new User());
    }

    /**
     * 实际上这里是不能处理这种异常的
     * 异常的处理方式，
     * 哪里出现了异常，直接抛出
     * 有ExceptionHandle去处理返回值
     * @return
     */
    @RequestMapping("ha")
    public String haHello(){
        if(true){
            throw new BussnessException("405","今天也是充满希望的一天！！！");
        }
        return JsonResponse.ERR(StatusCode.error,"今天也是充满希望的一天！！！");
    }

    @RequestMapping("error")
    public String error(){

        return JsonResponse.ERR(StatusCode.error,"今天下雨， 天气很不好！！！");
    }
    
}
